<template>
  <div class="login-container" style="height: 738px">
    <el-form
        class="login-form"
        autocomplete="on"
        v-model="userFrom"
        label-position="left">

      <div class="title-container">
        <h3 class="title">东安市能力有限公司<b>企业资源管理系统</b></h3>
      </div>

      <el-form-item prop="username">
        <span class="svg-container">
        </span>
        <el-input
            ref="email"
            placeholder="输入你的邮箱"
            name="email"
            v-model="userFrom.email"
            type="text"
            tabindex="1"
            autocomplete="on"

        />
      </el-form-item>

      <el-tooltip content="Caps lock is On" placement="right" manual>
        <el-form-item prop="password">
          <span class="svg-container">
          </span>
          <el-input
              placeholder="请输入密码"
              v-model="userFrom.password"
              name="password"
              tabindex="2"
              autocomplete="on"
          />
        </el-form-item>
      </el-tooltip>

      <el-button
          type="primary"
          style="width:100%;margin-bottom:30px;"
          @click.prevent="login"
      >登录
      </el-button>

      <div style="position:relative">
        <div class="tips">
          <span></span>
          <span></span>
        </div>
        <div class="tips">
          <span style="margin-right:18px;"></span>
          <span></span>
        </div>

        <el-button class="thirdparty-button" type="primary">
          联系管理员
        </el-button>
      </div>
    </el-form>

    <el-dialog title="或者联系我">
      不能对本地进行模拟，所以请结合您自己的商业模拟!！ ！
      <br>
      <br>
      <br>
      <social-sign/>
    </el-dialog>
  </div>
</template>
<script>
import axios from 'axios'
import cookie from 'js-cookie'
import request from '../request.js'
export default {
  name: 'login',
  data() {
    return {
      userFrom: {
        email: '',
        password: ''
      }
    }
  }, methods: {

    login(){
    axios.post("http://localhost:8150/user/login",this.userFrom).then(data =>{
        if (data.data.flag){
          //将获取的token字符串放到cookie中
          let token=data.data.data;
          //console.log(data.data.data)
          //参数:
          //第一个参数:cookie名称,第二个参数是value值,第三个参数作用范围
          cookie.set('erpDongAn-user',token,{domain:'localhost'});
          //调用接口,根据token信息获取用户信息,为了首页面的展示
          axios.get("http://localhost:8150/api/ucenter/wx/getMemberInfo").then(data =>{
            //将获取到的用户信息放到cookie中
            cookie.set('userInfo',data.data.data,{domain:'localhost'});
            this.$router.push({
              path:'/page'
            })
          }).catch(e=>{
            alert("错误信息为:"+e)
          })
        }
          this.$message({
                  showClose: true,
                  message: data.data.message,
                  type: data.data.flag == true ? 'success' : 'error'
                });
      }).catch(e =>{
        alert("错误信息为:"+e)
      })
    }

   /* login(){
      axios.post("http://localhost:8150/user/login",this.userFrom).then(data =>{
        console.log(data.data.data)
        console.log("flag:"+data.data.flag)
      }).catch(e =>{
        alert("错误信息为:"+e)
      })
    }*/
  }
}
</script>
<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

  .thirdparty-button {
    position: absolute;
    right: 0;
    bottom: 6px;
  }

  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }

}
</style>